<?php
	session_start();
	
	// 로그인 상태 확인
	if(!isset($_SESSION['usernm'])){
		header("Location: login.php");
	}
	
	if($_SERVER['REQUEST_METHOD']=='POST')
	{
		$id = $_POST['questid'];
	}
	else {
		echo "no id";
	}
?>

<!DOCTYPE html>
<html lang="ko"> 
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8"> 
<title>LifeQuest Quest page</title> 
<meta name="description" content="" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<meta http-equiv="X-UA-Compatible" content="IE=9" />

<link rel="stylesheet" href="css/bootstrap.css" type="text/css" />
<link rel="stylesheet" href="css/bootstrap-responsive.css" type="text/css" />
<link rel="stylesheet" href="css/style.css" type="text/css" />
<link rel="stylesheet" href="css/bootstrap_calendar.css" type="text/css" />

<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.8.3/jquery.min.js"></script>

<script src="js/bootstrap.js"></script>
<script src="js/lifequest.js"></script>
<script src="js/bootstrap_calendar.js"></script>

<!--[if lt IE 9]>
	<script src="http://html5shiv.googlecode.com/svn/trunk/html5.js"></script>	
<![endif]-->

<script type="text/javascript">
    $(document).ready( function(){
    	
    	$("#btn_del").click(function() {
			delete_quest("<?php echo $_POST['questid'] ?>");
		});
		$("#btn_chkin").click(function() {
			checkin(this, "<?php echo $_POST['questid'] ?>");
		});
        
    $(".collapse").collapse();
    
    theMonths = ["January", "February", "March", "April", "May", "June", "July", "August", "September", "October", "November", "December"];
    theDays = ["일", "월", "화", "수", "목", "금", "토"];
    
    res = ["27/6/2013", 
            'event tooltip'];
    rest = [res];
            
    $('#calendar_container').calendar({
        months: theMonths,
        days: theDays,
        events: rest
        
        // req_ajax: {
            // type: 'get',
            // url: 'json.php'
        // }
    });
});
</script>

</head>
<body>
	<div class="navbar ">
		<div class="navbar-inner">
			<div class="container">
				<a class="brand" href="./">Lifequest</a>
				<ul class="nav pull-right">
					<li class="dropdown">
						<a class="dropdown-toggle" data-toggle="dropdown">
							user : <?php echo $_SESSION['usernm'] ?>
							<b class="caret"></b>
						</a>
						<ul class="dropdown-menu">
							<li><a>user menu 1</a></li>
							<li><a>user menu 2</a></li>
						</ul>
					</li>
					<li>
						<a href="logout.php">Logout</a>		
					</li>
				</ul>
				
			</div>
		</div>    			
	</div>
	<div class="lq-container">	
		<div class="well " style="text-align:center">
			<?php 
				require_once('./php/quest.api.php');
                require_once('./php/checkin.api.php');
				
                // 퀘스트 정보 Retrieve
				$res = getQuestInfoPHP($_POST['questid']);
				
				if($res[result] == 'success')
				{
				    // 퀘스트 정보 출력
				    echo "<btn id='btn_del' class='btn btn-danger pull-right'><i class='icon-trash'></i> 이 퀘스트 지우기 </btn><br>";
					echo "<h2>" . "이름 : " . $res[quest_nm] . "</h2>";
					echo "<h3>" . "타입 : " . $res[quest_type] . "</h3>";
					echo "<h4>" . "빈도 : " . $res[quest_freq] . "</h4>";
					echo "<h4>" . "시작일 : " . $res[quest_start_date] . "~";
					if($res[quest_exp_date] != null)
					{
						echo "~" . "종료일 : " . $res[quest_exp_date] . "</h4>";
					}
					echo "<h4>" . "마지막 : " . $res[last_chk_date] . "</h4>";
					
					echo "<div class='progress' > <div class='bar' style='width: 60%;'>60%</div> </div>";
					
					$disabled = "";
					if($res[last_chk_date] == date("Y-m-d"))
						$disabled = " disabled";
					echo "<button id='btn_chkin' class='btn btn-large btn-primary" . $disabled . "' >체크인 </button>";
					echo "<br><a href='javascript:cancel_checkin(" . $_POST['questid'] . ")'>체크인 취소</a>";
                    
                    echo "<div class='accordion'>
                            <div class='accordion-group'>
                                <div class='accordion-heading'>
                                    <a class='accordion-toggle' data-toggle='collapse' href='#collapseContent'>
                                    달력 보기 </a>
                                </div>
                                <div id='collapseContent' class='accordion-body collapse in'>
                                    <div id='calendar_container'></div>
                                </div>
                            </div>
                        </div>";
                    
                    
                    // 과거 Checkin 정보 출력
                    $checkins = getCheckinsPHP($_POST['questid']);
                    
                    foreach($checkins as $checkin) {
                        echo $checkin[quest_chk_date];
                    }
				}
				else {
					
					echo "<h3>fail</h3>";
				}
			
			?>
			
		</div>
	</div>
	
</body>
</html>